﻿Public Class FrmHinhThucThanhToan
    Private selectedmahtt As String



    Private Sub btnNhapLai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNhapLai.Click
        btnSua.Text = "&Sửa"
        txtHTTT.Text = ""

    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        btnSua.Text = "&Sửa"
        If txtHTTT.Text <> "" Then
            If Not HinhThucThanhToan.them(txtHTTT.Text) Then
                MsgBox("Đã có hình thức thanh toán này!", MsgBoxStyle.Critical, "Lỗi")
            End If
            dgvHTTT.DataSource = HinhThucThanhToan.dsht()
            btnNhapLai_Click(sender, e)
        Else
            MsgBox("Bạn cần nhập thông tin đầy đủ của hình thức thanh toán", MsgBoxStyle.Information, "Thông báo")

        End If

    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        btnSua.Text = "&Sửa" 'nut sua viet kieu nay day, nhin xem
        dgvHTTT.DataSource = HinhThucThanhToan.timkiem(txtTuKhoa.Text)
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If btnSua.Text = "&Sửa" Then ' cai j day
            selectedmahtt = dgvHTTT.CurrentRow.Cells("MaHT").Value
            txtHTTT.Text = dgvHTTT.CurrentRow.Cells("TenHT").Value
            btnSua.Text = "&Lưu"
        Else
            If Not HinhThucThanhToan.capnhat(selectedmahtt, txtHTTT.Text) Then
                MsgBox("Không thể lưu được hình thức thanh toán này!", MsgBoxStyle.Critical, "Lỗi")
            End If
            btnSua.Text = "&Sửa"
            dgvHTTT.DataSource = HinhThucThanhToan.dsht()
            btnNhapLai_Click(sender, e)
        End If
    End Sub

    Private Sub FrmHinhThucThanhToan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btnSua.Text = "&Sửa"
        dgvHTTT.DataSource = HinhThucThanhToan.dsht()
    End Sub

    Private Sub btndaydu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndaydu.Click
        btnSua.Text = "&Sửa"
        dgvHTTT.DataSource = HinhThucThanhToan.dsht()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        btnSua.Text = "&Sửa"
        If (MsgBox("Bạn chắc chắn muốn xóa hình thức thanh toán này chứ?", MsgBoxStyle.YesNo, "Thông báo ") = DialogResult.Yes) Then
            If Not HinhThucThanhToan.xoa(dgvHTTT.CurrentRow.Cells("MaHT").Value) Then
                MsgBox("Bạn không thể xóa hình thức thanh toán này", MsgBoxStyle.Critical, "Lỗi")
            End If
        End If
        dgvHTTT.DataSource = HinhThucThanhToan.dsht()
        btnNhapLai_Click(sender, e)
    End Sub

    Private Sub dgvHTTT_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvHTTT.CellDoubleClick
        btnSua.Text = "&Sửa"
        btnSua_Click(sender, e)
    End Sub

    Private Sub dgvHTTT_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvHTTT.CellContentClick

    End Sub
End Class